package cn.iocoder.yudao.module.jifenyuan.controller.admin.roomlog;

import cn.iocoder.yudao.module.jifenyuan.controller.app.roomlog.vo.AppRoomLogRespVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.jifenyuan.controller.admin.roomlog.vo.*;
import cn.iocoder.yudao.module.jifenyuan.dal.dataobject.roomlog.RoomLogDO;
import cn.iocoder.yudao.module.jifenyuan.convert.roomlog.RoomLogConvert;
import cn.iocoder.yudao.module.jifenyuan.service.roomlog.RoomLogService;

@Tag(name = "管理后台 - 记分员 房间记录")
@RestController
@RequestMapping("/jifenyuan/room-log")
@Validated
public class RoomLogController {

    @Resource
    private RoomLogService roomLogService;

    @PostMapping("/create")
    @Operation(summary = "创建记分员 房间记录")
    @PreAuthorize("@ss.hasPermission('jifenyuan:room-log:create')")
    public CommonResult<Long> createRoomLog(@Valid @RequestBody RoomLogCreateReqVO createReqVO) {
        return success(roomLogService.createRoomLog(RoomLogConvert.INSTANCE.convert(createReqVO)));
    }

    @PutMapping("/update")
    @Operation(summary = "更新记分员 房间记录")
    @PreAuthorize("@ss.hasPermission('jifenyuan:room-log:update')")
    public CommonResult<Boolean> updateRoomLog(@Valid @RequestBody RoomLogUpdateReqVO updateReqVO) {
        roomLogService.updateRoomLog(RoomLogConvert.INSTANCE.convert(updateReqVO));
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除记分员 房间记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('jifenyuan:room-log:delete')")
    public CommonResult<Boolean> deleteRoomLog(@RequestParam("id") Long id) {
        roomLogService.deleteRoomLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得记分员 房间记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('jifenyuan:room-log:query')")
    public CommonResult<AppRoomLogRespVO> getRoomLog(@RequestParam("id") Long id) {
        RoomLogDO roomLog = roomLogService.getRoomLog(id);
        return success(RoomLogConvert.INSTANCE.convert(roomLog));
    }

    @GetMapping("/list")
    @Operation(summary = "获得记分员 房间记录列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('jifenyuan:room-log:query')")
    public CommonResult<List<AppRoomLogRespVO>> getRoomLogList(@RequestParam("ids") Collection<Long> ids) {
        List<RoomLogDO> list = roomLogService.getRoomLogList(ids);
        return success(RoomLogConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得记分员 房间记录分页")
    @PreAuthorize("@ss.hasPermission('jifenyuan:room-log:query')")
    public CommonResult<PageResult<AppRoomLogRespVO>> getRoomLogPage(@Valid RoomLogPageReqVO pageVO) {
        PageResult<RoomLogDO> pageResult = roomLogService.getRoomLogPage(RoomLogConvert.INSTANCE.convert(pageVO));
        return success(RoomLogConvert.INSTANCE.convertPage(pageResult));
    }



}
